
var MinStack = function() {
    this.stack = []
    this.helper = []
};

/** 
 * @param {number} val
 * @return {void}
 */
// 方法1：重复的数据元素比较多，这么做的话
// MinStack.prototype.push = function(val) {
//     this.stack.push(val)
//     // 辅助栈为0或者辅助栈当前最小值比val大
//     if(this.helper.length === 0 || this.helper[this.helper.length - 1] >= val) {
//         this.helper.push(x)
//     } else { // 当前最小值仍然是辅助栈栈顶的值
//         this.helper.push(this.helper[this.helper.length - 1])
//     }
// };
// /**
//  * @return {void}
//  */
// MinStack.prototype.pop = function() {
//     if(this.stack.length > 0) {
//         this.stack.pop()
//         this.helper.pop()
//     }
// };

/**
 * @return {number}
 */
MinStack.prototype.top = function() {
    return this.stack[this.stack.length - 1]
};

/**
 * @return {number}
 */
MinStack.prototype.getMin = function() {
    return this.helper[this.helper.length - 1]
};

// 方法2
MinStack.prototype.push = function(val) {
    this.stack.push(val)
    if(this.helper.length === 0 || this.helper[this.helper.length - 1] >= val) {
        this.helper.push(val)
    }
}
MinStack.prototype.pop = function() {
    let x = this.stack.pop()
    // 这里判断等于就行
    if(this.helper[this.helper.length - 1] >= x) {
        this.helper.pop()
    }
}

/**
 * Your MinStack object will be instantiated and called as such:
 * var obj = new MinStack()
 * obj.push(val)
 * obj.pop()
 * var param_3 = obj.top()
 * var param_4 = obj.getMin()
 */